<html>
<head><meta charset="utf-8"><title>Question on implied bounds · wg-traits · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/index.html">wg-traits</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Question.20on.20implied.20bounds.html">Question on implied bounds</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="209040518"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Question%20on%20implied%20bounds/near/209040518" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Stefan Zabka <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Question.20on.20implied.20bounds.html#209040518">(Sep 03 2020 at 23:23)</a>:</h4>
<p>I just read this sentence in the <a href="https://rust-lang.github.io/chalk/book/clauses/implied_bounds.html">chalk book</a></p>
<blockquote>
<p>Note that in the loud_insert example, HashSet&lt;K&gt; is not the type of the set argument of loud_insert, it only appears in the argument type &amp;mut HashSet&lt;K&gt;: we care about every type appearing in the function's header (the header is the signature without the return type), not only types of the function's arguments.</p>
</blockquote>
<p>Does this mean the following function does not have the implicit bound of <code>K:Hash</code></p>
<div class="codehilite"><pre><span></span><code><span class="k">fn</span> <span class="nf">create_with_item</span><span class="o">&lt;</span><span class="n">K</span><span class="o">&gt;</span><span class="p">(</span><span class="n">item</span>: <span class="nc">K</span><span class="p">)</span><span class="w">  </span>-&gt;  <span class="nc">HashSet</span><span class="o">&lt;</span><span class="n">K</span><span class="o">&gt;</span><span class="p">{</span><span class="w"></span>
<span class="w">   </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">set</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">HashSet</span>::<span class="n">new</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="n">set</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="n">item</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="n">set</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p><a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018">It currently isn't</a> but I also don't know how to activate chalk on the playground, so sorry for not checking that.</p>
<p>If this is intended to stay like this, could you explain why? I'd then also create a PR against the book so the reasons would be documented.</p>



<a name="209045241"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Question%20on%20implied%20bounds/near/209045241" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Question.20on.20implied.20bounds.html#209045241">(Sep 04 2020 at 00:44)</a>:</h4>
<p>Your play.rust-lang link doesn't go where you think</p>



<a name="209045549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Question%20on%20implied%20bounds/near/209045549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Question.20on.20implied.20bounds.html#209045549">(Sep 04 2020 at 00:50)</a>:</h4>
<p>So, at the  end of that section there is the following text:</p>
<blockquote>
<p>Implied bounds are not yet completely enforced in rustc, at the moment it only works for outlive requirements, super trait bounds, and bounds on associated types.</p>
</blockquote>



<a name="209045580"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Question%20on%20implied%20bounds/near/209045580" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Question.20on.20implied.20bounds.html#209045580">(Sep 04 2020 at 00:51)</a>:</h4>
<p>In that example, there could be an implicit bound of <code>K: Hash</code></p>



<a name="209045594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Question%20on%20implied%20bounds/near/209045594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Question.20on.20implied.20bounds.html#209045594">(Sep 04 2020 at 00:51)</a>:</h4>
<p>But I'm not 100% sure Chalk does that</p>



<a name="209045663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Question%20on%20implied%20bounds/near/209045663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Question.20on.20implied.20bounds.html#209045663">(Sep 04 2020 at 00:52)</a>:</h4>
<p>I don't think you can pass <code>-Z</code> options in the playground</p>



<a name="209076650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Question%20on%20implied%20bounds/near/209076650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Stefan Zabka <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Question.20on.20implied.20bounds.html#209076650">(Sep 04 2020 at 10:20)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/144729-wg-traits/topic/Question.20on.20implied.20bounds/near/209045241">said</a>:</p>
<blockquote>
<p>Your play.rust-lang link doesn't go where you think</p>
</blockquote>
<p>Sorry <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;code=use%20std%3A%3Acollections%3A%3AHashSet%3B%0Afn%20create_with_item%3CK%3E(item%3A%20K)%20%20-%3E%20%20HashSet%3CK%3E%7B%0A%20%20%20let%20mut%20set%20%3D%20HashSet%3A%3Anew()%3B%0A%20%20%20%20set.insert(item)%3B%0A%20%20%20%20set%0A%7D">correct link</a></p>



<a name="209076770"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Question%20on%20implied%20bounds/near/209076770" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Stefan Zabka <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Question.20on.20implied.20bounds.html#209076770">(Sep 04 2020 at 10:22)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232957">Jack Huey</span> <a href="#narrow/stream/144729-wg-traits/topic/Question.20on.20implied.20bounds/near/209045580">said</a>:</p>
<blockquote>
<p>In that example, there could be an implicit bound of <code>K: Hash</code></p>
</blockquote>
<p>Okay, thanks. To me it read as if there was an explicit reason that the return type would be left out for inferring implied bounds and I was wondering what it was.</p>
<p>So this is basically documenting current behaviour and not the desired state?</p>



<a name="209076816"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Question%20on%20implied%20bounds/near/209076816" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Question.20on.20implied.20bounds.html#209076816">(Sep 04 2020 at 10:23)</a>:</h4>
<p>My understanding (of the docs) is that chalk implements implied bounds but rust doesn't yet</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>